package com.users.rn.kit

import com.users.rn.common.init.ALHReactNativeInit
import com.users.rn.kit.bridge.RNBridge
import com.users.rn.kit.bridge.impl.KitLifeCycleBridge
import com.users.rn.kit.bridge.impl.broadcast.KitBroadcastEmitter
import com.users.rn.kit.bridge.impl.im.IMBridge
import com.users.rn.kit.bridge.impl.net.NetworkBridge
import com.users.rn.kit.bridge.impl.route.KitRouterBridge
import com.users.rn.kit.bridge.impl.sign.SignBridge
import com.users.rn.rncommon.basic.RNReactModulesPackage
import com.users.rn.rncommon.init.RNInitInterface

/**

 * 作者：wolf on 12/22/20 09:46

 * 邮箱：bluce

 */

object RNKitManager {
    val bridgeList: MutableMap<String, RNBridge> = mutableMapOf()

    fun kitInit(rnCommonImpl: RNInitInterface): RNKitManager {

        //初始化自定义module
        RNReactModulesPackage.registerNativeModule(
            KitLifeCycleBridge::class.java,
            NetworkBridge::class.java,
            KitRouterBridge::class.java,
            IMBridge::class.java,
            SignBridge::class.java,
            KitBroadcastEmitter::class.java
        )
        ALHReactNativeInit.initialize(rnCommonImpl)
        return this
    }

    fun <T : RNBridge> register(vararg bridges: T) {
        bridges.forEach {
            bridgeList[it.moduleName()] = it
        }
    }

    inline fun <reified T : RNBridge> get(moduleName: String): T? {
        return bridgeList[moduleName] as T?
    }
}